import Vue from 'vue'
import VueRouter from 'vue-router'
import Movie from '../views/home/Movie.vue'

Vue.use(VueRouter)

const routes = [
  {path:"/",redirect: "home"},
  {
    path: '/home',
    name: 'Movie',
    component: Movie,
    children:[
      {path:"/home",redirect: "/home/reying"},
      {path:"reying",name:"reying",component:()=>import(/* webpackChunkName: "reying" */ '../views/home/reying.vue')},
      {path:"yingyuan",name:"yingyuan",component:()=>import(/* webpackChunkName: "yingyuan" */ '../views/home/yingyuan.vue')},
      {path:"daiying",name:"daiying",component:()=>import(/* webpackChunkName: "daiying" */ '../views/home/daiying.vue')},
      {path:"jingdian",name:"jingdian",component:()=>import(/* webpackChunkName: "jingdian" */ '../views/home/jingdian.vue')}
    ]
  },
  {
    path: '/video',
    name: 'Video',
    component: () => import(/* webpackChunkName: "video" */'../views/Video.vue')
  },
  {
    path: '/minvideo',
    name: 'MinVideo',
    component: () => import(/* webpackChunkName: "MinVideo" */ '../views/MinVideo.vue')
  },
  {
    path: '/show',
    name: 'Show',
    component: () => import(/* webpackChunkName: "Show" */'../views/Show.vue')
  },
  {
    path: '/me',
    name: 'Me',
    component: () => import(/* webpackChunkName: "Me" */ '../views/Me.vue')
  },
  {
    path: '/item/:id',//动态路由
    name: 'Item',
    component: () => import(/* webpackChunkName: "item" */ '../views/Item.vue')
  },
   {
    path: '/logoin',//登录路由
    name: 'logoin',
    component: () => import(/* webpackChunkName: "logoin" */ '../views/logoin.vue')
  },
  {
    path: '/city',//城市路由
    name: 'City',
    component: () => import(/* webpackChunkName: "city" */ '../views/City.vue')
  },
  {
    //404路由配置放在末尾
    path: '*',//动态路由
    name: 'page404',
    component: () => import(/* webpackChunkName: "page404" */ '../views/page404.vue')
  },
]

const router = new VueRouter({
  routes
})

//添加全局守卫
router.beforeEach((to, from, next) => {
 if(to.path == '/me'){
   //判断登陆状态
  if(sessionStorage.getItem('logoType')){
    next();
  }else{
    next('/logoin');
  }
 }else{
   next();
 }
})
export default router
